package itheima.com.testlistfragmentdemo.fragment;


import android.widget.Toast;

import java.util.List;

import itheima.com.testlistfragmentdemo.MyApplication;
import itheima.com.testlistfragmentdemo.R;
import itheima.com.testlistfragmentdemo.adapter.NewsAdapter;
import itheima.com.testlistfragmentdemo.base.BaseListAdpater;
import itheima.com.testlistfragmentdemo.base.BaseListFragment;
import itheima.com.testlistfragmentdemo.entity.News;
import itheima.com.testlistfragmentdemo.entity.NewsList;
import itheima.com.testlistfragmentdemo.net.OSChinaAPI;
import itheima.com.testlistfragmentdemo.utils.XmlUtils;


public class NewsInfoFragment extends BaseListFragment<News> {


    @Override
    protected List<News> parseData(byte[] data) {
        NewsList newsList= XmlUtils.toBean(NewsList.class,data);
        return newsList.getList();
    }

    @Override
    public BaseListAdpater getListAdapter() {
        return new NewsAdapter();
    }

    @Override
    public void sendRequestData() {
//        String url="http://10.0.2.2:8080/oschina/list/news/page1.xml";
        String url="/oschina/list/news/page1.xml";
//        OSChinaApi.getData(url,listener);
        OSChinaAPI.getNewsList(0,listener);
    }
    @Override
    public int getLayout() {
        return super.getLayout();
    }

    @Override
    public void onRefresh() {
        MyApplication.getHandler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(getActivity(), "刷新结束", Toast.LENGTH_SHORT).show();
                mRefreshLayout.setRefreshing(false);
            }
        },3000);


    }

}
